﻿using System;
using NUnit.Framework;
using ScrumBox.Model;

namespace ScrumBox.UnitTests.Model
{
    [TestFixture]
    public class ProjectTester
    {
        [Test]
        public void CanCreateProject()
        {
            var projectName = "New Project";
            var startDate = DateTime.Now;
            var projectKey = "NEW_PROJECT$";

            var project = new Project(projectName, projectKey, startDate);

            Assert.AreEqual(project.Name, projectName);
            Assert.AreEqual(project.Key, projectKey);
            Assert.AreEqual(project.StartDate, startDate);
        }

        [Test]
        public void CanAddProductBackLogItems()
        {
            var project = new Project();
            var description = "A Description";
            var title = "MyBackLogItem";
            var item = new ProductBackLogItem(title, description);
            project.AddProductBackLogItem(item);
            project.AddProductBackLogItem(new ProductBackLogItem());
            project.AddProductBackLogItem(new ProductBackLogItem());
            
            Assert.That(project.GetProductBacklogItems().Count == 3);
            Assert.That(project.GetProductBacklogItems().Contains(item));
            var referencedItem = project.GetProductBacklogItems()[0];
            Assert.That(item == referencedItem);
        }

        [Test]
        public void CanAddSprint()
        {
            var project = new Project {Key = "MyProject"};

            project.AddSprint(new Sprint(project));
            project.AddSprint(new Sprint(project));
            project.AddSprint(new Sprint(project));
            
            var sprintTitle = "Sprint 12";
            var sprintKey = string.Format("{0}-{1}", project.Key, sprintTitle);
            
            var sprint = new Sprint(sprintKey, sprintTitle, DateTime.Now, DateTime.Now + TimeSpan.FromDays(14));
            project.AddSprint(sprint);
            
            Assert.That(project.GetSprint(sprint.Title) == sprint);
            Assert.That(project.GetSprints().Count == 4);
            Assert.That(sprint.Project == project);
        }
    }
}